package com.jiangong.controller;

import com.jiangong.entity.Result;
import com.jiangong.util.AliyunOSSOperator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
public class UploadController {
    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;
    @RequestMapping("/upload")
    @ResponseBody
    public Result uploadFile(MultipartFile file) throws Exception {
        String originalFilename = file.getOriginalFilename();
        byte[] bytes = file.getBytes();
        String url = aliyunOSSOperator.upload(bytes,originalFilename);
        return new Result().success(url);
    }
}
